package cn.ecut;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * @Author: luodean
 * @ClassName: JDBC02
 * @Description: 基础的插入数据
 * @Date: Created in 21:20 2020/9/14
 */
public class JDBC02 {
    public static void main(String[] args) throws Exception {
        //注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //获取数据库连接
        String Url = "jdbc:mysql://localhost:3306/test?serverTimezone = Asia/Shanghai";
        String Username = "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(Url, Username, password);
        //获取 Statement 对象
        Statement statement = connection.createStatement();
        //执行 Sql 语句
        //values后可以插入多条数据
        String sql = " insert into test01 ( name , password ) values ('余二狗' , 5555689 ) , ('余心痒' , 456789 )";
        int executeUpdate = statement.executeUpdate( sql );
        //获取结果
        System.out.println( executeUpdate );
        //释放资源
        statement.close();
        connection.close();
    }
}
